package com.chixing.day02;

import java.util.Arrays;

public class ArrayDemo {
    public static void main(String[] args){
        int[] arr1 ={10,20,30,40,50};
        for (int i=0;i<arr1.length;i++){
            System.out.println(arr1[i]);
        }
        int[] arr2 =new int[5]; //5:元素个数
        for (int j=0;j<arr2.length;j++){
            System.out.println(arr2[j]);
        }

        float[] arr3={9.9f,4.5f,3.6f,12};
        float[] arr4=new float[5];

        //arr1=null;

        System.out.println(arr3[0]);
        //System.out.println(arr3[6]); //ArrayIndexOutOfBoundsException

        //2行3列
        int[][] a={{1,2,3},{2,3,4}};
        System.out.println("a[0][2]:"+a[0][2]);
        System.out.println("a的行数:"+a.length);//行数
        System.out.println("a的列数:"+a[0].length);//列数
        int[][] b= new int[2][3];

        int[][] c=new int[2][]; //错误的定义方式
        System.out.println("a的行数:"+c.length);//行数 2
//        c[0][0] =1;//错误的

        //数组的工具类:Arrays
        int[] newArr= Arrays.copyOf(arr1,10);
        for (int x=0;x<newArr.length;x++){
            System.out.println(newArr[x]);
        }

        //三目运算
        int x=10;
        int y=20;
        int z=(x>y)?x:y;
        System.out.println(z);

    }
    public static int fun1(){
        int x=10;
        int y=20;
        return (x>y)?x:y;
    }
}
